/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    int kthToLast(ListNode* head, int k) {
        ListNode* cur = head;
        ListNode* prev = head;
        while (k--)
            prev = prev->next;
        while (prev)
        {
            cur = cur->next;
            prev = prev->next;
        }
        return cur->val;
    }
};